package com.micro.ai.template.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.micro.ai.template.entity.TemplateTag;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 模板标签Mapper
 *
 * @author micro-ai
 * @since 0.0.1
 */
@Mapper
public interface TemplateTagMapper extends BaseMapper<TemplateTag> {

    /**
     * 根据模板ID查询标签
     */
    @Select("SELECT t.* FROM template_tags t " +
            "INNER JOIN template_tag_relations r ON t.id = r.tag_id " +
            "WHERE r.template_id = #{templateId}")
    List<TemplateTag> selectByTemplateId(@Param("templateId") String templateId);

    /**
     * 查询热门标签
     */
    @Select("SELECT * FROM template_tags ORDER BY use_count DESC LIMIT #{limit}")
    List<TemplateTag> selectHotTags(@Param("limit") Integer limit);

    /**
     * 根据类型查询标签
     */
    @Select("SELECT * FROM template_tags WHERE tag_type = #{tagType} ORDER BY use_count DESC")
    List<TemplateTag> selectByType(@Param("tagType") String tagType);
}

